package com.carlwang.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;

import com.carlwang.pojo.MyTask;
import com.carlwang.pojo.TaskList;
import com.carlwang.service.TaskDaoService;
import com.opensymphony.xwork2.ActionSupport;
import com.task.MyTimerTask;

public class PlayMediaAction extends ActionSupport {
	/**
	 * 
	 */

	private static final long serialVersionUID = 1L;
	private TaskDaoService mTaskDaoService;

	private TaskList mTaskList;
	private MyTask mMyTask;

	public String playMusic() {

		String currentDate = getMyTask().getStartTime();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
		Date date = null;
		try {
			date = sdf.parse(currentDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		MyTimerTask task = new MyTimerTask();
		Timer timer = new Timer();
		if (date == null) {
			return INPUT;
		}
		timer.schedule(task, date);
		return SUCCESS;

	}

	public String saveTask() {
		String state = playMusic();
		if (state.equals(INPUT)) {
			return INPUT;
		}
		getTaskDaoService().save(getTaskList(), getMyTask());
		return SUCCESS;
	}

	public TaskDaoService getTaskDaoService() {
		return mTaskDaoService;
	}

	public void setTaskDaoService(TaskDaoService taskDaoService) {
		mTaskDaoService = taskDaoService;
	}

	public TaskList getTaskList() {
		return mTaskList;
	}

	public void setTaskList(TaskList taskList) {
		mTaskList = taskList;
	}

	public MyTask getMyTask() {
		return mMyTask;
	}

	public void setMyTask(MyTask myTask) {
		mMyTask = myTask;
	}

}
